<template>
  <div style="background: #fff">
    <div class="title">
     <div>{{title}}</div>
    </div>
    <div style="padding: 1.875rem">
      <el-form :inline="true">
        <!-- <el-form-item label="">
          <el-input
            v-model="query.name"
            placeholder="订单号"
            clearable
          ></el-input>
        </el-form-item> -->
        <el-form-item label="选择类型">
          <el-select v-model="query.vip_id" placeholder="请选择"  clearable>
            <el-option
              v-for="item in vip_type"
              :key="item.id"
              :label="item.name"
              :value="item.id"
            ></el-option>
          </el-select>
        </el-form-item>
         <el-form-item label="选择城市" >
          <el-select v-model="query.city_id" placeholder="请选择"  clearable>
            
            <el-option
              v-for="item in city"
              :key="item.id"
              :label="item.name"
              :value="item.id"
            ></el-option>
          </el-select>
        </el-form-item>
       
        <el-form-item label="日期筛选">
          <el-date-picker
             v-model="date"
            type="daterange"
            align="right"
            unlink-panels
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            @change="getDateRange"
            format="yyyy-MM-dd"
           
            :picker-options="pickerOptions"
          >
          </el-date-picker>
        </el-form-item>
    
        <el-form-item>
          <el-button type="success" @click="getPageData(true)">查询</el-button>
          <el-button @click="reset">重置</el-button>
         
        </el-form-item>
      </el-form>
    </div>
    <div ref="chart1" style="width: 100%; height: 400px"></div>
     <div ref="chart2" style="width: 100%; height: 400px"></div>
     <!-- <div class="sta">
     开卡总数：{{pages.total}}
    </div> -->
    <el-table :data="data" stripe style="width: 100%" >
      <el-table-column prop="id" label="id"></el-table-column>
      <el-table-column prop="total_price" label="付款金额"></el-table-column>
      <el-table-column prop="order_sn" label="流水号"></el-table-column>
      <el-table-column label="会员头像" >
          <template slot-scope="scope">
            <el-image
              :src="
                cdn+scope.row.user.icon+
                '?imageView2/1/w/50/h/50/format/webp/q/75|imageslim' 
              "
              :preview-src-list="[cdn+scope.row.user.big_icon ]"
            >
            </el-image>
          </template>
        </el-table-column>
      <el-table-column label="会员昵称">
        <template slot-scope="scope">
          {{scope.row.user.nick_name}}
        </template>
      </el-table-column>
    
       <el-table-column label="类型">
        <template slot-scope="scope">
          {{['月卡','季卡','年卡'][(scope.row.vip_id-1)]}}
        </template>
      </el-table-column>

       
    <el-table-column prop="pay_at" label="付款时间"></el-table-column>
     
      
     
      
    
    </el-table>
    <el-pagination
      v-if="data.length>0"
      background
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="pages.currentPage"
     
      :page-size="pages.per_page"
      layout="total,prev, pager, next"
      :total="pages.total"
      style="text-align: center"
    >
    </el-pagination>
   
  
    
  </div>
</template>

<script>
import mixin from "../../js/mixin";

export default {
  name: "homePage",
  mixins: [mixin],
  data() {
    return {
      is_check:false,
      is_page: true,
      api_url: "order/vip",
      one: [],
      two:[],
      item: {},
      vip_type:[{
        id:1,
        name:'月卡'
      },{
        id:2,
        name:'季卡'
      },{
        id:3,
        name:'年卡'
      }],
      query: {
        city_id:'',
        vip_id:''
      },
    };
  },
  components: {},
  mounted() {
   
  },
  created() {
    this.type = localStorage.getItem('admin_type')
    this.title = this.$route.meta.title
    this.init()
  },
  methods: {
    reset() {
      this.query = {}
      this.getData(true)
    },
    init(){
       this.getCity()
      this.getData()
      this.getTrend()
      this.getPriceTrend()
    },
    
    
    showEdit(e) {
      let { href } = this.$router.resolve({
        name: "shopDetail",
        params: { id:e },
        query: {
         
        }
      });
      window.open(href, "_blank");
    },


   getTrend() {
      this.global.httpRequest("trend/vip", this.query).then((res) => {
        this.getEchartData1(res);
      });
    },

    getPriceTrend() {
      this.global.httpRequest("trend/vipPrice", this.query).then((res) => {
        this.getEchartData2(res);
      });
    },

     getEchartData1(e) {
      const chart = this.$refs.chart1;
      if (chart) {
        const myChart = this.$echarts.init(chart);
        let x = e.x;
        let y = e.y;

        let title = "每日开卡次数 开卡总数："+e.total;
        const option = this.getEchartOption(x, y, title);
        myChart.setOption(option);
        window.addEventListener("resize", function () {
          myChart.resize();
        });
      }
    },

    getEchartData2(e) {
      const chart = this.$refs.chart2;
      if (chart) {
        const myChart = this.$echarts.init(chart);
        let x = e.x;
        let y = e.y;
        let title = "每日开卡金额 开卡总金额："+e.total;
        const option = this.getEchartOption(x, y, title);
        myChart.setOption(option);
        window.addEventListener("resize", function () {
          myChart.resize();
        });
      }
    },
   

   
   
  },
};
</script>

<style scoped>




</style>
